home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / C / x12c.c < prev    next >
C/C++ Source or Header  |  1994-06-30  |  2KB  |  100 lines

  1. /* $Id: x12c.c,v 1.7 1994/06/30 17:57:49 mjl Exp $
  2.  * $Log: x12c.c,v $
  3.  * Revision 1.7  1994/06/30  17:57:49  mjl
  4.  * All C example programs: made another pass to eliminate warnings when using
  5.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  6.  * (now included by plplot.h), eliminated redundant casts, put in more
  7.  * uniform comments, and other minor changes.
  8.  *
  9.  * Revision 1.6  1994/03/30  07:21:56  mjl
  10.  * Changes to all C example programs: special handling for malloc re: header
  11.  * files eliminated, include of stdio.h and stdlib.h eliminated (now done
  12.  * by plplot.h), include of "plplot.h" changed to <plplot.h> to enable
  13.  * simpler builds by the general user, some cleaning up also.
  14. */
  15.  
  16. /*    x12c.c
  17.  
  18.     Bar chart demo.
  19. */
  20.  
  21. #include <plplot.h>
  22.  
  23. void
  24. plfbox(PLFLT x0, PLFLT y0);
  25.  
  26. /*----------------------------------------------------------------------*\
  27.  * main
  28.  *
  29.  * Does a simple bar chart, using color fill.  If color fill is
  30.  * unavailable, pattern fill is used instead (automatic).
  31. \*----------------------------------------------------------------------*/
  32.  
  33. int
  34. main(int argc, char *argv[])
  35. {
  36.     int i;
  37.     char string[20];
  38.     PLFLT y0[10];
  39.  
  40. /* Parse and process command line arguments */
  41.  
  42.     (void) plParseInternalOpts(&argc, argv, PL_PARSE_FULL);
  43.  
  44. /* Initialize plplot */
  45.  
  46.     plinit();
  47.  
  48.     pladv(0);
  49.     plvsta();
  50.     plwind(1980.0, 1990.0, 0.0, 35.0);
  51.     plbox("bc", 1.0, 0, "bcnv", 10.0, 0);
  52.     plcol(2);
  53.     pllab("Year", "Widget Sales (millions)", "#frPLplot Example 12");
  54.  
  55.     y0[0] = 5;
  56.     y0[1] = 15;
  57.     y0[2] = 12;
  58.     y0[3] = 24;
  59.     y0[4] = 28;
  60.     y0[5] = 30;
  61.     y0[6] = 20;
  62.     y0[7] = 8;
  63.     y0[8] = 12;
  64.     y0[9] = 3;
  65.  
  66.     for (i = 0; i < 10; i++) {
  67.     plcol(i + 1);
  68.     plpsty(0);
  69.     plfbox((1980. + i), y0[i]);
  70.     sprintf(string, "%.0f", y0[i]);
  71.     plptex((1980. + i + .5), (y0[i] + 1.), 1.0, 0.0, .5, string);
  72.     sprintf(string, "%d", 1980 + i);
  73.     plmtex("b", 1.0, ((i + 1) * .1 - .05), 0.5, string);
  74.     }
  75.  
  76.     /* Don't forget to call PLEND to finish off! */
  77.  
  78.     plend();
  79.     exit(0);
  80. }
  81.  
  82. void
  83. plfbox(PLFLT x0, PLFLT y0)
  84. {
  85.     PLFLT x[4], y[4];
  86.  
  87.     x[0] = x0;
  88.     y[0] = 0.;
  89.     x[1] = x0;
  90.     y[1] = y0;
  91.     x[2] = x0 + 1.;
  92.     y[2] = y0;
  93.     x[3] = x0 + 1.;
  94.     y[3] = 0.;
  95.     plfill(4, x, y);
  96.     plcol(1);
  97.     pllsty(1);
  98.     plline(4, x, y);
  99. }
  100.